﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using GameLibrary;
using Rescue_of_the_Dwarvenzombies.SceneObjects;

namespace Rescue_of_the_Dwarvenzombies.SceneLayers
{
    public abstract class SceneLayer : ISceneLayer
    {
        protected Game _game;

        /// <summary>
        /// Gets or sets the scene objects.
        /// </summary>
        /// <value>
        /// The scene objects.
        /// </value>
        protected List<ISceneObject> SceneObjects { get; set; }

        /// <summary>
        /// Gets the child.
        /// </summary>
        public ISceneLayer Child { get; protected set; }

        /// <summary>
        /// Gets the name of the layer.
        /// </summary>
        /// <value>
        /// The name of the layer.
        /// </value>
        public Constant.Layer LayerName { get; protected set; }

        /// <summary>
        /// Gets the depth.
        /// </summary>
        public float Depth { get; protected set; }

        /// <summary>
        /// Inits the objects.
        /// </summary>
        protected abstract void InitObjects();

        /// <summary>
        /// Initializes a new instance of the <see cref="SceneLayer"/> class.
        /// </summary>
        /// <param name="game">The game.</param>
        protected SceneLayer(Game game)
        {
            _game = game;
            SceneObjects = new List<ISceneObject>();
        }

        /// <summary>
        /// Updates the objects
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public void Update(GameTime gameTime)
        {
            //Make a copy of the original list in order to be able to change the set
            List<ISceneObject> copy = new List<ISceneObject>(SceneObjects);

            foreach (ISceneObject sceneObject in copy)
            {
                sceneObject.Update(gameTime);
            }

            if (Child != null)
                Child.Update(gameTime);
        }

        /// <summary>
        /// Gets the scene objects.
        /// </summary>
        /// <returns></returns>
        public virtual List<ISceneObject> GetSceneObjects()
        {
            return SceneObjects;
        }

        /// <summary>
        /// Removes the scene object.
        /// </summary>
        /// <param name="sceneObjectToRemove">The scene object to remove.</param>
        public virtual void RemoveSceneObject(ISceneObject sceneObjectToRemove)
        {
            SceneObjects.Remove(sceneObjectToRemove);
        }
    }
}